package com.fmatos.amazingwallpapers.service.image;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

import com.fmatos.amazingwallpapers.service.image.BitmapsService.LocalBinder;

public class BitmapServiceConnection implements ServiceConnection {

	private boolean mBound = false;
	private BitmapsService mService = null;


	/**
	 * Creates object and binds myself to activity
	 * @param context
	 */
	public BitmapServiceConnection(Context context) {
		Intent intent = new Intent(context, BitmapsService.class);
		context.bindService(intent, this, Context.BIND_AUTO_CREATE);
	}
	
	@Override
	public void onServiceConnected(ComponentName className,
			IBinder service) {
		// We've bound to LocalService, cast the IBinder and get LocalService instance
		LocalBinder binder = (LocalBinder) service;
		mService = binder.getService();
		mBound = true;
	}

	@Override
	public void onServiceDisconnected(ComponentName arg0) {
		mBound = false;
	}

	public boolean isBound() {
		return mBound;
	}

	public BitmapsService getService() {
		return mService;
	}

}
